package cn.itcast.service.impl;

import cn.itcast.dao.UserDao;
import cn.itcast.pojo.UserInfo;
import cn.itcast.service.UserService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;


@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public UserDetails loadUserByUsername(String username) {
        UserInfo userInfo = userDao.getUserByName(username);
        if(null == userInfo){
            throw new UsernameNotFoundException("用户不存在");
        }
        userInfo.setRoleList(userDao.getRolesById(userInfo.getId()));
        return userInfo;
    }
}
